<!DOCTYPE html>
<html>
#{include file="header.html"}#
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <h5><i class="fa fa-home"></i> 商品SKU列表</h5>
          <div class="ibox-tools"><a href="javascript:void(0);" class="btn btn-xs btn-default btn-help-detail" data-type="goods_sku"> <i class="fa fa-question-circle"> 操作说明</i></a></div>
        </div>
        <div class="ibox-content table-responsive">
          <div class="row">
            <form id="pagerForm" method="post"  class="form-inline">
              <div class="col-sm-3 m-b-xs"> 
				  <a href="?" class="btn btn-default"> <i class='fa fa-refresh'></i>刷新</a>
				  <a class="btn btn-info" href="#{$smarty.const.ACT}#/goods/Goods/goods_add/">发布商品</a>
                <div class="btn-group">
                  <button data-toggle="dropdown" class="btn btn-default dropdown-toggle">批量操作 <span class="caret"></span></button>
                  <ul class="dropdown-menu">
                    <li class="divider"></li>
                    <li><a href="javascript:void(0)" class="batch_operation" data-act="del">批量删除</a></li>
                  </ul>
                </div>
              </div>
              <div class="col-sm-9 m-b-xs text-right">
                <div class="input-group pd-b-5">
                  <input type="text" name="goods_name" placeholder="请输入商品名字关键词" class="form-control">
                </div>
                <div class="btn-group">
                  <button data-toggle="dropdown" class="btn  dropdown-toggle"><span class="caret"></span></button>
                  <div class="dropdown-menu">
                    <div class="ibox-content">
                      <div class="form-group">
                        <label>店铺名称</label>
                        <input type="text" name="name" placeholder="搜索店铺名称" class="form-control">
                      </div>
                      <div class="form-group">
                        <label>手机号</label>
                        <input type="text" name="mobile" placeholder="搜索店铺手机号" class="form-control">
                      </div>
                      <div class="form-group">
                        <label>联系地址</label>
                        <input type="text" name="content" placeholder="搜索店铺联系地址" class="form-control">
                      </div>
                      <div class="form-group">
                        <button type="button" class="btn btn-primary btn-xs btn-block ajaxSearchForm"><i class="fa fa-search"></i> 搜索</button>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="input-group"> <span class="input-group-btn">
                  <button type="button" class="btn btn-primary ajaxSearchForm"><i class="fa fa-search"></i> 搜索</button>
                  </span> </div>
              </div>
            </form>
          </div>
          <table class="table table-hover sorttable 07fly-table" width="100%">
            <thead>
              <tr>
                <th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
                <th>商品名称</th>
                <th>商品规格</th>
				  		<th width="120" orderField="by_stock" class="sort-filed"><span>库存</span></th>
                <th width="120" align="center" orderField="by_sale_price" class="sort-filed"><span>销售价格</span></th>
                <th width="120" align="center" orderField="by_market_price" class="sort-filed"><span>市场价格</span></th>
                <th width="120" align="center" orderField="by_cost_price" class="sort-filed"><span>成本单价</span></th>
                <th width="120" align="center" orderField="by_total_cost_money" class="sort-filed"><span>成本总金额</span></th>
                <th width="120" orderField="by_total_profit_money" class="sort-filed"><span>预计利润</span></th>
                <th width="50">操作</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
            <tfoot class="ibox-content">
              <tr>
                <td colspan="8" align="center"></td>
              </tr>
            </tfoot>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>
<script id="tableListTpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><input name="sku_id" class="checkboxCtrlId" value="<%=list[i]['sku_id']%>" type="checkbox"></td>
		<td><%=list[i]['goods_name']%></td>
		<td><%=list[i]['sku_name']%></td>
		<td><%=list[i]['stock']%></td>
		<td><%=list[i]['sale_price']%></td>
		<td><%=list[i]['market_price']%></td>
		<td><%=list[i]['cost_price']%></td>
		<td><%=list[i]['total_cost_money']%></td>
		<td><%=list[i]['total_profit_money']%></td>
		<td width='10'>
			<p><a href="javascript:void(0)" class="single_operation" data-id="<%=list[i]['sku_id']%>" data-act="modify">修改</a></p>
			<p><a href="javascript:void(0)" class="single_operation" data-id="<%=list[i]['sku_id']%>" data-act="del">删除</a></p>

		</td>
	</tr>
<% } %>
</script>
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script>
<script type="text/javascript">
var ajaxUrl='#{$smarty.const.ACT}#/goods/GoodsSku/goods_sku_json/';
$(document).ready(function () {
	turnPage(1);//页面加载时初始化分页

	$("body").on("click", ".batch_operation", function() {
		batch_act =$(this).attr("data-act")
		var chk_value =[]; 
    	$("tbody input[class='checkboxCtrlId']:checked").each(function(){ 
        chk_value.push($(this).val()); 
		}); 
		goods_id_txt=chk_value.join(",");
		if(batch_act=="del"){
			act_url="#{$smarty.const.ACT}#/goods/Goods/goods_del/";
		}
	});
	
	$("body").on("click", ".single_operation", function() {
		sku_id =$(this).attr("data-id");
		single_act =$(this).attr("data-act")
		if(single_act=="modify"){
			layer.open({
				type: 2,
				title: '修改商品单品',
				shadeClose: true,
				fixed: false, //不固定
				area: ['90%', '90%'],
				content: '#{$smarty.const.ACT}#/goods/GoodsSku/goods_sku_modify/sku_id/'+sku_id,
				end: function () {
					turnPage(1);//页面加载时初始化分页
				}
			});			
			return false;	
		}else if(single_act=="del"){
			act_url="#{$smarty.const.ACT}#/goods/GoodsSku/goods_sku_del/";
			layer.confirm('确定删除吗？有库存的商品无法删除！', {
			  btn: ['确定','取消'] //按钮
			}, function(){
				$.ajax({
					type: "POST",
					url: act_url,
					data:{"sku_id":sku_id},
					dataType:"json",
					success: function(data){
						if(data.statusCode=='200'){
							layer.msg('操作成功', {icon: 1}); 
							turnPage(1);
						}
					}
				});
				layer.closeAll('dialog');
			});
		}
		
	});
	
	
});
</script>